﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Speed_of_live_and_deed
{
    class Police
    {
        /// <summary>
        /// 各种常量
        /// </summary>
        public Rectangle Rectangle { get; set; }
        private int SpeedX;
        private int SpeedY;
        private int role = 1;
        private int Rank;
        private int Class;
        public String UserInput = " ";
        /// <summary>
        ///  定义矩形
        /// </summary>
        /// <param name="rec"></param>
        public Police(Rectangle rec)
        {
            Rectangle = rec;
            SpeedX = -6;
            SpeedY = -3;
        }
        /// <summary>
        /// 难度系数为困难
        /// </summary>
        public void btnDiffculty_Click()
        {
            Rank = 2;
           
        }
        public void btnOrdinary_Click()
        {
            Rank = 3;
        }
        public void btnEasy_Click()
        {
            Rank = 4;
        }
        //绘制图案
        public void Draw(Graphics g)
        {
            g.TranslateTransform(dx: 0, dy: 0);
            if (role == 1)
            {
                g.DrawImage(Properties.Resources.photo2, Rectangle);
            }
            if (role == 2)
            {
                g.DrawImage(Properties.Resources.photo22, Rectangle);
            }
            if (role == 3)
            {
                g.DrawImage(Properties.Resources.photo23, Rectangle);
            }
            if (role == 4)
            {
                g.DrawImage(Properties.Resources.photo24, Rectangle);
            }
            //draw the Inputwords
            Rectangle recWords = new Rectangle(100, 600, 800, 50);
            g.DrawString(UserInput, new Font("宋体", 24), new SolidBrush(Color.Red), recWords);

        }

        /// <summary>
        ///  处理键盘(笨方法)
        /// </summary>
        /// <param name="key"></param>
        public void KeyDown(string key)
        {
            if (key.ToUpper() == "A" && UserInput == " ")
            {
                if (key.ToUpper().ToString() == "A")
                {
                    UserInput = "A";
                    Chose();
                }
            }
            if (key.ToUpper() == "B" && UserInput == "A")
            {
                if (key.ToUpper().ToString() == "B")
                {
                    UserInput = "AB";
                    Chose();
                }
            }
            if (key.ToUpper() == "C" && UserInput == "AB")
            {
                if (key.ToUpper().ToString() == "C")
                {
                    UserInput = "ABC";
                    Chose();

                }
            }
            if (key.ToUpper() == "D" && UserInput == "ABC")
            {
                if (key.ToUpper().ToString() == "D")
                {
                    UserInput = "ABCD";
                    Chose();

                }

            }
            if (key.ToUpper() == "E" && UserInput == "ABCD")
            {
                if (key.ToUpper().ToString() == "E")
                {
                    UserInput = "ABCDE";
                    Chose();

                }

            }
            if (key.ToUpper() == "F" && UserInput == "ABCDE")
            {
                if (key.ToUpper().ToString() == "F")
                {
                    UserInput = "ABCDEF";
                    Chose();

                }
            }
            if (key.ToUpper() == "G" && UserInput == "ABCDEF")
            {
                if (key.ToUpper().ToString() == "G")
                {
                    UserInput = "ABCDEFG";
                    Chose();

                }
            }
            if (key.ToUpper() == "H" && UserInput == "ABCDEFG")
            {
                if (key.ToUpper().ToString() == "H")
                {
                    UserInput = "ABCDEFGH";
                    Chose();

                }
            }
            if (key.ToUpper() == "I" && UserInput == "ABCDEFGH")
            {
                if (key.ToUpper().ToString() == "I")
                {
                    UserInput = "ABCDEFGHI";
                    Chose();
                }
            }
            if (key.ToUpper() == "J" && UserInput == "ABCDEFGHI")
            {
                if (key.ToUpper().ToString() == "J")
                {
                    UserInput = "ABCDEFGHIJ";
                    Chose();

                }
            }
            if (key.ToUpper() == "K" && UserInput == "ABCDEFGHIJ")
            {
                if (key.ToUpper().ToString() == "K")
                {
                    UserInput = "ABCDEFGHIJK";
                    Chose();

                }
            }
            if (key.ToUpper() == "L" && UserInput == "ABCDEFGHIJK")
            {
                if (key.ToUpper().ToString() == "L")
                {
                    UserInput = "ABCDEFGHIJKL";
                    Chose();

                }
            }
            if (key.ToUpper() == "M" && UserInput == "ABCDEFGHIJKL")
            {
                if (key.ToUpper().ToString() == "M")
                {
                    UserInput = "ABCDEFGHIJKLM";
                    Chose();

                }
            }
            if (key.ToUpper() == "N" && UserInput == "ABCDEFGHIJKLM")
            {
                if (key.ToUpper().ToString() == "N")
                {
                    UserInput = "ABCDEFGHIJKLMN";
                    Chose();

                }
            }
            if (key.ToUpper() == "O" && UserInput == "ABCDEFGHIJKLMN")
            {
                if (key.ToUpper().ToString() == "O")
                {
                    UserInput = "ABCDEFGHIJKLMNO";
                    Chose();

                }
            }
            if (key.ToUpper() == "P" && UserInput == "ABCDEFGHIJKLMNO")
            {
                if (key.ToUpper().ToString() == "P")
                {
                    UserInput = "ABCDEFGHIJKLMNOP";
                    Chose();

                }
            }
            if (key.ToUpper() == "Q" && UserInput == "ABCDEFGHIJKLMNOP")
            {
                if (key.ToUpper().ToString() == "Q")
                {
                    UserInput = "ABCDEFGHIJKLMNOPQ";
                    Chose();

                }
            }
            if (key.ToUpper() == "R" && UserInput == "ABCDEFGHIJKLMNOPQ")
            {
                if (key.ToUpper().ToString() == "R")
                {
                    UserInput = "ABCDEFGHIJKLMNOPQR";
                    Chose();

                }
            }
            if (key.ToUpper() == "S" && UserInput == "ABCDEFGHIJKLMNOPQR")
            {
                if (key.ToUpper().ToString() == "S")
                {
                    UserInput = "ABCDEFGHIJKLMNOPQRS";
                    Chose();
                }
            }
            if (key.ToUpper() == "T" && UserInput == "ABCDEFGHIJKLMNOPQRS")
            {
                if (key.ToUpper().ToString() == "T")
                {
                    UserInput = "ABCDEFGHIJKLMNOPQRST";
                    Chose();
                }
            }
            if (key.ToUpper() == "U" && UserInput == "ABCDEFGHIJKLMNOPQRST")
            {
                if (key.ToUpper().ToString() == "U")
                {
                    UserInput = "ABCDEFGHIJKLMNOPQRSTU";
                    Chose();
                }
            }
            if (key.ToUpper() == "V" && UserInput == "ABCDEFGHIJKLMNOPQRSTU")
            {
                if (key.ToUpper().ToString() == "V")
                {
                    UserInput = "ABCDEFGHIJKLMNOPQRSTUV";
                    Chose();
                }
            }
            if (key.ToUpper() == "W" && UserInput == "ABCDEFGHIJKLMNOPQRSTUV")
            {
                if (key.ToUpper().ToString() == "W")
                {
                    UserInput = "ABCDEFGHIJKLMNOPQRSTUVW";
                    Chose();
                }
            }
            if (key.ToUpper() == "X" && UserInput == "ABCDEFGHIJKLMNOPQRSTUVW")
            {
                if (key.ToUpper().ToString() == "X")
                {
                    UserInput = "ABCDEFGHIJKLMNOPQRSTUVWX";
                    Chose();
                }
            }
            if (key.ToUpper() == "Y" && UserInput == "ABCDEFGHIJKLMNOPQRSTUVWX")
            {
                if (key.ToUpper().ToString() == "Y")
                {
                    UserInput = "ABCDEFGHIJKLMNOPQRSTUVWXY";
                    Chose();
                }
            }
            if (key.ToUpper() == "Z" && UserInput == "ABCDEFGHIJKLMNOPQRSTUVWXY")
            {
                if (key.ToUpper().ToString() == "Z")
                {
                    UserInput = " ";
                    Chose();
                    Class += 1;
                }
            }

        }
        /// <summary>
        /// 移动函数
        /// </summary>
        private void Move()
        {

            this.Rectangle = new Rectangle(this.Rectangle.X + SpeedX, this.Rectangle.Y + SpeedY, 50, 60);
            //判断各个点的坐标
            if (this.Rectangle.X <= 162 && this.Rectangle.X >= 162 && this.Rectangle.Y <= 354 && this.Rectangle.Y >= 354)
            {
                this.Rectangle = new Rectangle(this.Rectangle.X + SpeedX, this.Rectangle.Y + SpeedY, 50, 60);
                SpeedX *= -1;
                role = 1;
            }
            if (this.Rectangle.X <= 200 & this.Rectangle.Y <= 318 & this.Rectangle.Y >= 318)
            {
                this.Rectangle = new Rectangle(this.Rectangle.X + SpeedX, this.Rectangle.Y + SpeedY, 50, 60);
                SpeedX *= -1;
                role = 2;
            }
            if (this.Rectangle.X >= 324 & this.Rectangle.X <= 324 & this.Rectangle.Y <= 201 & this.Rectangle.Y >= 201)
            {
                SpeedX *= -1;
                this.Rectangle = new Rectangle(this.Rectangle.X + SpeedX, this.Rectangle.Y + SpeedY, 50, 60);
                role = 1;
            }
            if (this.Rectangle.X >= 216 & this.Rectangle.X <= 216 & this.Rectangle.Y <= 147 & this.Rectangle.Y >= 147)
            {
                this.Rectangle = new Rectangle(this.Rectangle.X + SpeedX, this.Rectangle.Y + SpeedY, 50, 60);
                SpeedX *= -1;
                role = 2;
            }
            if (this.Rectangle.X <= 390 & this.Rectangle.X >= 390 & this.Rectangle.Y <= 60)
            {
                this.Rectangle = new Rectangle(this.Rectangle.X + SpeedX, this.Rectangle.Y + SpeedY, 50, 60);
                SpeedY *= -1;
                role = 3;
            }
            if (this.Rectangle.X <= 546 & this.Rectangle.X >= 546 & this.Rectangle.Y <= 138)
            {
                this.Rectangle = new Rectangle(this.Rectangle.X + SpeedX, this.Rectangle.Y + SpeedY, 50, 60);
                SpeedY *= -1;
                role = 2;
            }
            if (this.Rectangle.X >= 690 & this.Rectangle.X <= 690 & this.Rectangle.Y <= 66)
            {
                this.Rectangle = new Rectangle(this.Rectangle.X + SpeedX, this.Rectangle.Y + SpeedY, 50, 60);
                SpeedY *= -1;
                role = 3;
            }
            if (this.Rectangle.X >= 900 & this.Rectangle.X <= 900 & this.Rectangle.Y <= 171)
            {
                this.Rectangle = new Rectangle(this.Rectangle.X + SpeedX, this.Rectangle.Y + SpeedY, 50, 60);
                SpeedX *= -1;
                role = 4;
            }
            if (this.Rectangle.X <= 216 & this.Rectangle.X >= 216 & this.Rectangle.Y >= 513)
            {
                this.Rectangle = new Rectangle(210, 510, 50, 60);
                this.Rectangle = new Rectangle(this.Rectangle.X + SpeedX, this.Rectangle.Y + SpeedY, 50, 60);
                SpeedY *= -1;
                role = 1;
            }
            if (this.Rectangle.X <= 30 & this.Rectangle.Y <= 420 & this.Rectangle.Y >= 420)
            {
                this.Rectangle = new Rectangle(30, 420, 50, 60);
                SpeedX *= -1;
                this.Rectangle = new Rectangle(this.Rectangle.X + SpeedX, this.Rectangle.Y + SpeedY, 50, 60);
                role = 2;
            }
        }
        /// <summary>
        /// 定义选择难度函数
        /// </summary>
        private void Chose()
        {
            if (Rank == 2)
            {
                Diffculty();
                Class = 2;
            }
            if (Rank == 3)
            {
                Ordinary();
                Class = 3;
            }
            if (Rank == 4)
            {
                easy();
                Class = 4;
            }
        }
        /// <summary>
        /// 定义难度困难
        /// </summary>
        private void Diffculty()
        {
            switch (Class)
            {
                case 2:
                    Move();
                    Move();
                    break;
                case 3:
                    Move();
                    Move();
                    Move();
                    break;
                case 4:
                    Move();
                    Move();
                    Move();
                    Move();
                    break;
                case 5:
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    break;
                case 6:
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    break;
                default:
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    break;
            }
        }
        /// <summary>
        /// 定义难度一般
        /// </summary>
        private void Ordinary()
        {
            switch (Class)
            {
                case 3:
                    Move();
                    Move();
                    Move();
                    break;
                case 4:
                    Move();
                    Move();
                    Move();
                    Move();
                    break;
                case 5:
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    break;
                case 6:
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    break;
                case 7:
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    break;
                default:
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    break; ;
            }
        }
        /// <summary>
        ///  定义难度简单
        /// </summary>
        private void easy()
        {
            switch (Class)
            {
                case 4:
                    Move();
                    Move();
                    Move();
                    Move();
                    break;
                case 5:
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    break;
                case 6:
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    break;
                case 7:
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    break;
                case 8:
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    break;
                default:
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    Move();
                    break;
            }
        }

    }
}
